<template>
  <div class="page-cont">
    <van-nav-bar
      title="添加钢筋加工记录"
      left-arrow
      @click-left="$router.go(-1)"
    />
    <div class="list">
      <action-select
        v-model="form.rebarTypeId"
        title="钢筋类型"
        :list="preData.steelDeviceType"
        label="rebarType"
        value="id"
      />
      <action-select
        v-model="form.rebarDeviceId"
        title="钢筋设备"
        :list="preData.steelDevice"
        label="deviceName"
        value="id"
      />
      <action-select
        v-model="form.prodType"
        title="加工类型"
        :list="prodTypeOption"
      />
      <div class="b" />
      <van-field
        label="加工数量"
        placeholder="请输入"
        type="number"
        input-align="right"
        v-model="form.prodNum"
      />
      <time-select
        v-model="form.gmtStart"
        title="开始时间"
      />
      <time-select
        v-model="form.gmtEnd"
        title="结束时间"
      />
    </div>
    <van-button
      class="bottom"
      type="info"
      block
      @click="onConfirm"
    >
      提交
    </van-button>
  </div>
</template>

<script>
export default {
  name: "SteelProductAppend",
  components: {},
  data() {
    return {
      prodTypeOption: [
        {
          label: "剪切",
          value: 0,
        },
        {
          label: "弯曲",
          value: 1,
        },
        {
          label: "调直",
          value: 2,
        },
        {
          label: "锯",
          value: 3,
        },
        {
          label: "箍",
          value: 4,
        },
        {
          label: "绑扎",
          value: 5,
        },
      ],
      form: {
        rebarDeviceId: "",
        rebarTypeId: "",
        prodType: '',
        prodNum: null,
        gmtStart: "",
        gmtEnd: "",
      },
    };
  },
  created() {},
  methods: {
    async onConfirm() {
      // 判断
      if (!this.form.rebarDeviceId) return this.$toast.fail('请选择钢筋设备');
      if (!this.form.rebarTypeId) return this.$toast.fail('请选择钢筋类型');
      if (!this.form.prodType) return this.$toast.fail('请选择加工类型');
      if (!this.form.prodNum) return this.$toast.fail('请输入加工数量');
      if (!this.form.gmtStart) return this.$toast.fail('请选择开始时间');
      if (!this.form.gmtEnd) return this.$toast.fail('请选择结束时间');
      this.form.fieldId = this.$store.state.user.userInfo.unitId

      this.$toast.loading({  message: '加载中...', forbidClick: true });
      await this.api.ADD_STEEL_PRODUCT_RECORD(this.form)
      this.$toast.clear()
      this.$router.back()
    }
  },
};
</script>

<style lang="scss" scoped>
@import "./style.scss";
.page-cont {
  background: #f5f5f5;
  .bottom {
    border-radius: 0;
  }
  .list {
    flex: 1;
    height: 0;
    overflow: hidden;
    overflow-y: auto;
    .b {
      height: 10px;
    }
  }
}
</style>
